package com.ruoyi.web.controller.warning;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.warning.domain.entity.Config;
import com.ruoyi.warning.service.IConfigService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author chenhc
 * @since 2025-07-15
 */
@RestController
@RequestMapping("/config")
@Api(tags = "系统配置", description = "用于处理系统配置相关操作的控制器")
public class ConfigController {

    @Resource
    private IConfigService configService;

    @ApiOperation("获取配置")
    @GetMapping(value = "/get/{name}")
    public R getIndexPage(@PathVariable String name)
    {
        Wrapper<Config> wrapper = new QueryWrapper<Config>().lambda()
                .eq(Config::getConfigName,name)
                .last("limit 1");
        Config config = configService.getOne(wrapper);
        return R.ok(config);
    }

    @ApiOperation("新增或修改配置")
    @PostMapping(value = "/saveOrUpdate")
    public R getIndexPage(@RequestBody Config config)
    {
        configService.saveOrUpdate(config);
        return R.ok();
    }
}
